layui.define(['jquery', 'layer','paging', 'code','form','element','upload','laydate'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        upload = layui.upload,
        laydate = layui.laydate,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var therole = "";
    $.ajax({
        type:"GET",
        url:contextPath+"/personal/role",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            therole = data.role;
            if(data.role=="管理员"||data.role=="船厂"||data.role=="船东"){
                $('#add').show();
            }
        },
        error: function (e) {
        }
    });


    paging.init({
        url: contextPath + "/project/ops/all", //地址
        elem: '#con', //内容容器
        type: 'GET',
        //new
        key: '#s_type',
        value: '#s_value',
        params: { //发送到服务端的参数
        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
            if(therole=="管理员"){
                $('.moress').show();
                $('.moress1').show();
                $('.quality').show();
                $('.record').show();
                $('.doc').show();
                $('.itemOp').show();
            }else if(therole=="负责人"){
                $('.moress').show();
                $('.moress1').show();
                $('.quality').show();
                $('.record').show();
                $('.doc').show();
            }else if(therole=="验船师"){
                $('.moress').show();
                $('.quality').show();
                $('.record').show();
                $('.doc').show();
                $('.log').show();
            }else if(therole=="船厂"||therole=="船东"){
                $('.moress').show();
                $('.quality').show();
                $('.record').show();
                $('.doc').show();
            }else{

            }
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调

        },
    });

    $("body").on("click",".itemOp",function () {
        var inspnum = $(this).data('id');

        layer.open({
            type:1,
            title: '选择操作'
            ,id: 'itemOp' //设定一个id，防止重复弹出
            ,area: ['250px', '150px']
            ,content: '<div style="padding-left: 50px ;padding-top:20px;padding-bottom:25px;width:200px">' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-small forbidd" data-id="'+inspnum+'">禁用</a>' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-warm layui-btn-small reneww" data-id="'+inspnum+'">恢复</a>' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-danger layui-btn-small deletee" data-id="'+inspnum+'">删除</a>' +
            '</div>'
        });
    });

    $("body").on("click",".log",function(){
        var rgstnum = $(this).data('id');

        parent.layui.element().tabAdd('demo', {
            title: rgstnum+' 日志列表',
            content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=LogList/OperaLogList.html?rgstnum='+rgstnum+'></iframe>',
            id: 'log'+ rgstnum
        });
        parent.layui.element().tabChange('demo', 'log'+ rgstnum);
        parent.layui.element().init();

    });

    $("body").on("click",".doc",function(){
        var rgstnum = $(this).data('id');

        parent.layui.element().tabAdd('demo', {
            title: rgstnum+' 文档列表',
            content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=DocList/OperaDocList.html?rgstnum='+rgstnum+'></iframe>',
            id: 'doc'+ rgstnum
        });
        parent.layui.element().tabChange('demo', 'doc'+ rgstnum);
        parent.layui.element().init();

    });

    $("body").on("click",".record",function(){
        var rgstnum = $(this).data('id');
        $.ajax({
            type: "GET",
            url: contextPath + "/project/ops/" + rgstnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                if(data.state=="禁用"){
                    layer.msg('该营运检验项目已被禁用' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else if(data.auditstate&&data.auditstate=="同意受理"){
                    var ctdate="",ljdate="",dqdate="";

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/ops/ct/"+ rgstnum ,
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            if(data.ctdate){
                                ctdate = data.ctdate;
                            }
                        },
                        error:function(e){
                        }
                    });
                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/ops/lj/"+ rgstnum ,
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            if(data.ljdate){
                                ljdate = data.ljdate;
                            }
                        },
                        error:function(e){
                        }
                    });
                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/ops/dq/"+ rgstnum ,
                        async: false,
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            if(data.dqdate){
                                dqdate = data.dqdate;
                            }
                        },
                        error:function(e){
                        }
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/personal/role",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if(data.role=="管理员"||data.role=="验船师"){
                                parent.layui.element().tabAdd('demo', {
                                    title: '船检登记号 '+rgstnum+' 效用实验记录',
                                    content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=ExperRecord/OperaExperRecord.html?rgstnum='+rgstnum+'></iframe>',
                                    id: 'flag'+ rgstnum
                                });
                                parent.layui.element().tabChange('demo', 'flag'+ rgstnum);
                                parent.layui.element().init();
                            }else if(data.role=="船东"||data.role=="船厂"||data.role=="负责人"){
                                if(ctdate==""&&ljdate==""&&dqdate==""){
                                    layer.msg('效用实验记录<br>未创建' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }else{
                                   parent.layui.element().tabAdd('demo', {
                                        title: '船检登记号 '+rgstnum+' 效用实验记录',
                                        content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=ExperRecord/OperaExperRecord.html?rgstnum='+rgstnum+'></iframe>',
                                        id: 'flag'+ rgstnum
                                    });
                                    parent.layui.element().tabChange('demo', 'flag'+ rgstnum);
                                    parent.layui.element().init(); 
                                }
                            }else{

                            }
                        },
                        error:function(e){
                        }
                    });
                }else if(data.auditstate&&data.auditstate=="不予受理"){
                    layer.msg('申请表已审核<br>不予受理' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else{
                    layer.msg('申请表未审核' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error: function (e) {
            }
        });
    });

    $("body").on("click",".quality",function(){
        var rgstnum = $(this).data('id');

        $.ajax({
            type: "GET",
            url: contextPath + "/project/ops/qcc/" + rgstnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.qccdate){
                    if(therole=="船东"&&!data.cdopn){
                        $.ajax({
                            type: "GET",
                            url: contextPath + "/project/ops/" + rgstnum,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (datas) {
                                if(datas.state!="禁用"&&datas.auditstate&&datas.auditstate=="同意受理"){
                                    $.get('OperaQualityDetails.html',function(OperaQualityDetails) {
                                        index = layer.open({
                                            type: 1,
                                            title: '质量控制表',
                                            content: OperaQualityDetails,
                                            area: ['auto', '600px'],
                                            maxmin: false,
                                            success:function (layero,index) {
                                                console.log(data);

                                                $('input[name="shipname"]').attr("value",data.shipname);
                                                $('input[name="rgstnum"]').attr("value",data.rgstnum);
                                                $('input[name="qccdate"]').attr("value",data.qccdate);
                                                $('input[name="qccname"]').attr("value",data.qccname);
                                                $('textarea[name="test3"]').val(data.test3);
                                                $('input[name="cdopndate"]').attr("value",getNowFormatDate());

                                                if(data.test1){
                                                    $('input[name="test1"]').attr("checked","checked");
                                                    $('input[name="qtest1"]').attr("checked","checked");
                                                }
                                                if(data.test2d1){
                                                    $('input[name="test2d1"]').attr("checked","checked");
                                                    $('input[name="qtest2d1"]').attr("checked","checked");
                                                }
                                                if(data.test2d2){
                                                    $('input[name="test2d2"]').attr("checked","checked");
                                                    $('input[name="qtest2d2"]').attr("checked","checked");
                                                }
                                                if(data.test2d3){
                                                    $('input[name="test2d3"]').attr("checked","checked");
                                                    $('input[name="qtest2d3"]').attr("checked","checked");
                                                }
                                                if(data.test2d4){
                                                    $('input[name="test2d4"]').attr("checked","checked");
                                                    $('input[name="qtest2d4"]').attr("checked","checked");
                                                }
                                                if(data.test2d5){
                                                    $('input[name="test2d5"]').attr("checked","checked");
                                                    $('input[name="qtest2d5"]').attr("checked","checked");
                                                }
                                                if(data.test2d6){
                                                    $('input[name="test2d6"]').attr("checked","checked");
                                                    $('input[name="qtest2d6"]').attr("checked","checked");
                                                }
                                                if(data.test2d7){
                                                    $('input[name="test2d7"]').attr("checked","checked");
                                                    $('input[name="qtest2d7"]').attr("checked","checked");
                                                }
                                                if(data.test2d8){
                                                    $('input[name="test2d8"]').attr("checked","checked");
                                                    $('input[name="qtest2d8"]').attr("checked","checked");
                                                }
                                                if(data.test2d9){
                                                    $('input[name="test2d9"]').attr("checked","checked");
                                                    $('input[name="qtest2d9"]').attr("checked","checked");
                                                }
                                                if(data.test2d10){
                                                    $('input[name="test2d10"]').attr("checked","checked");
                                                    $('input[name="qtest2d10"]').attr("checked","checked");
                                                }

                                                $('#cdopn1').hide();
                                                $('#cdopn2').show();
                                                $('#xxx').hide();
                                                $('#zzz').show();

                                                $('#xu').on('click',function () {
                                                    window.open('../../print/opera/OperaQualityTable/OperaQualityTable.html?rgstnum='+rgstnum);
                                                    return false;
                                                });

                                                $('#submitt').on('click',function () {
                                                    $(this).attr('disabled','disabled');
                                                    var ss = new Object();

                                                    ss.rgstnum = $('input[name="rgstnum"]').val();
                                                    ss.cdopn = $('select[name="cdopn"] option:selected').val();

                                                    $.ajax({
                                                        type:"PUT",
                                                        url:contextPath+"/project/ops/qcc/updateCd",
                                                        contentType: "application/json; charset=utf-8",
                                                        data: JSON.stringify(ss),
                                                        dataType:"json",
                                                        success:function (data) {
                                                            console.log(data.message);
                                                            if(data.message == "更新质量控制表成功!"){
                                                                layer.msg('质量控制表更新成功!<br>页面将在1秒后刷新...');
                                                                setTimeout(function(){window.location.reload();},1000);
                                                            } else {
                                                                $('#submit').attr('disabled',false);
                                                                layer.msg(data.message, {
                                                                    time:false,
                                                                    btn:"确定",
                                                                    btnAlign: 'c'
                                                                });
                                                                $("#all-info").html("*"+data.message);
                                                            }
                                                        },
                                                        error:function (e) {
                                                        }
                                                    });
                                                    return false;
                                                });
                                            },
                                            yes: function(index) {
                                                console.log(index);
                                            },
                                            full: function(elem) {
                                                var win = window.top === window.self ? window : parent.window;
                                                $(win).on('resize', function() {
                                                    var $this = $(this);
                                                    elem.width($this.width()).height($this.height()).css({
                                                        top: 0,
                                                        left: 0
                                                    });
                                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                                });
                                            }
                                        });
                                        form.render();
                                    });
                                }else if(datas.state=="禁用"){
                                    layer.msg('该营运检验项目已被禁用' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }else if(datas.auditstate&&datas.auditstate=="不予受理"){
                                    layer.msg('申请表已审核<br>不予受理' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }else{
                                    layer.msg('申请表未审核' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }
                            },
                            error: function (e) {
                            }
                        });
                    }else{
                        $.ajax({
                            type: "GET",
                            url: contextPath + "/project/ops/" + rgstnum,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (datas) {
                                if(datas.state!="禁用"&&datas.auditstate&&datas.auditstate=="同意受理"){
                                    $.get('OperaQualityDetails.html',function(OperaQualityDetails) {
                                        index = layer.open({
                                            type: 1,
                                            title: '质量控制表',
                                            content: OperaQualityDetails,
                                            area: ['auto', '600px'],
                                            maxmin: false,
                                            success:function (layero,index) {
                                                console.log(data);

                                                $('input[name="shipname"]').attr("value",data.shipname);
                                                $('input[name="rgstnum"]').attr("value",data.rgstnum);
                                                $('input[name="qccdate"]').attr("value",data.qccdate);
                                                $('input[name="qccname"]').attr("value",data.qccname);
                                                $('textarea[name="test3"]').val(data.test3);
                                                if(data.cdopn){
                                                    $('input[name="cdopn"]').attr("value",data.cdopn);
                                                    $('input[name="cdopndate"]').attr("value",data.cdopndate);
                                                }

                                                if(data.test1){
                                                    $('input[name="test1"]').attr("checked","checked");
                                                    $('input[name="qtest1"]').attr("checked","checked");
                                                }
                                                if(data.test2d1){
                                                    $('input[name="test2d1"]').attr("checked","checked");
                                                    $('input[name="qtest2d1"]').attr("checked","checked");
                                                }
                                                if(data.test2d2){
                                                    $('input[name="test2d2"]').attr("checked","checked");
                                                    $('input[name="qtest2d2"]').attr("checked","checked");
                                                }
                                                if(data.test2d3){
                                                    $('input[name="test2d3"]').attr("checked","checked");
                                                    $('input[name="qtest2d3"]').attr("checked","checked");
                                                }
                                                if(data.test2d4){
                                                    $('input[name="test2d4"]').attr("checked","checked");
                                                    $('input[name="qtest2d4"]').attr("checked","checked");
                                                }
                                                if(data.test2d5){
                                                    $('input[name="test2d5"]').attr("checked","checked");
                                                    $('input[name="qtest2d5"]').attr("checked","checked");
                                                }
                                                if(data.test2d6){
                                                    $('input[name="test2d6"]').attr("checked","checked");
                                                    $('input[name="qtest2d6"]').attr("checked","checked");
                                                }
                                                if(data.test2d7){
                                                    $('input[name="test2d7"]').attr("checked","checked");
                                                    $('input[name="qtest2d7"]').attr("checked","checked");
                                                }
                                                if(data.test2d8){
                                                    $('input[name="test2d8"]').attr("checked","checked");
                                                    $('input[name="qtest2d8"]').attr("checked","checked");
                                                }
                                                if(data.test2d9){
                                                    $('input[name="test2d9"]').attr("checked","checked");
                                                    $('input[name="qtest2d9"]').attr("checked","checked");
                                                }
                                                if(data.test2d10){
                                                    $('input[name="test2d10"]').attr("checked","checked");
                                                    $('input[name="qtest2d10"]').attr("checked","checked");
                                                }

                                                $.ajax({
                                                    type:"GET",
                                                    url:contextPath+"/personal/role",
                                                    contentType: "application/json; charset=utf-8",
                                                    dataType: "json",
                                                    success: function (data) {
                                                        console.log(data.role);
                                                        if(data.role!="管理员"){
                                                            $('#edit').hide();
                                                        }
                                                    },
                                                    error: function (e) {

                                                    }
                                                });

                                                $('#su').on('click',function () {
                                                    window.open('../../print/opera/OperaQualityTable/OperaQualityTable.html?rgstnum='+rgstnum);
                                                    return false;
                                                });

                                                $('#edit').on('click',function () {
                                                    $('#xxx').hide();
                                                    $('#sss').show();
                                                    $('.quality1').hide();
                                                    $('.quality2').show();

                                                    $('input[name="qccdate"]').attr('disabled', false);
                                                    $('input[name="qccname"]').attr('disabled', false);
                                                    $('textarea[name="test3"]').attr('disabled', false);

                                                    $('input[name="qccdate"]').attr('class', 'layui-input');
                                                    $('input[name="qccname"]').attr('class', 'layui-input');
                                                    $('textarea[name="test3"]').attr('class', 'layui-textarea');

                                                    return false;

                                                });

                                                $('#submit').on('click',function () {
                                                    $(this).attr('disabled','disabled');
                                                    var ss = new Object();

                                                    ss.rgstnum = $('input[name="rgstnum"]').val();
                                                    ss.qccname = $('input[name="qccname"]').val();
                                                    ss.test1 = $('input[name="qtest1"]').is(':checked');
                                                    ss.test2d1 = $('input[name="qtest2d1"]').is(':checked');
                                                    ss.test2d2 = $('input[name="qtest2d2"]').is(':checked');
                                                    ss.test2d3 = $('input[name="qtest2d3"]').is(':checked');
                                                    ss.test2d4 = $('input[name="qtest2d4"]').is(':checked');
                                                    ss.test2d5 = $('input[name="qtest2d5"]').is(':checked');
                                                    ss.test2d6 = $('input[name="qtest2d6"]').is(':checked');
                                                    ss.test2d7 = $('input[name="qtest2d7"]').is(':checked');
                                                    ss.test2d8 = $('input[name="qtest2d8"]').is(':checked');
                                                    ss.test2d9 = $('input[name="qtest2d9"]').is(':checked');
                                                    ss.test2d10 = $('input[name="qtest2d10"]').is(':checked');
                                                    ss.test3 = $('textarea[name="test3"]').val();

                                                    $.ajax({
                                                        type:"PUT",
                                                        url:contextPath+"/project/ops/qcc/update",
                                                        contentType: "application/json; charset=utf-8",
                                                        data: JSON.stringify(ss),
                                                        dataType:"json",
                                                        success:function (data) {
                                                            console.log(data.message);
                                                            if(data.message == "更新质量控制表成功!"){
                                                                layer.msg('质量控制表更新成功!<br>页面将在1秒后刷新...');
                                                                setTimeout(function(){window.location.reload();},1000);
                                                            } else {
                                                                $('#submit').attr('disabled',false);
                                                                layer.msg(data.message, {
                                                                    time:false,
                                                                    btn:"确定",
                                                                    btnAlign: 'c'
                                                                });
                                                                $("#all-info").html("*"+data.message);
                                                            }
                                                        },
                                                        error:function (e) {
                                                        }
                                                    });
                                                    return false;
                                                });
                                            },
                                            yes: function(index) {
                                                console.log(index);
                                            },
                                            full: function(elem) {
                                                var win = window.top === window.self ? window : parent.window;
                                                $(win).on('resize', function() {
                                                    var $this = $(this);
                                                    elem.width($this.width()).height($this.height()).css({
                                                        top: 0,
                                                        left: 0
                                                    });
                                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                                });
                                            }
                                        });
                                        form.render();
                                    });
                                }else if(datas.state=="禁用"){
                                    layer.msg('该营运检验项目已被禁用' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }else if(datas.auditstate&&datas.auditstate=="不予受理"){
                                    layer.msg('申请表已审核<br>不予受理' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }else{
                                    layer.msg('申请表未审核' , {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }
                            },
                            error: function (e) {
                            }
                        });
                    }
                } else {
                    $.ajax({
                        type:"GET",
                        url:contextPath+"/personal/role",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if(data.role=="管理员"||data.role=="验船师"){
                                $.ajax({
                                    type: "GET",
                                    url: contextPath + "/project/ops/" + rgstnum,
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (data) {
                                        console.log(data);
                                        if(data.state=="禁用"){
                                            layer.msg('该营运检验项目已被禁用' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }else if(data.auditstate&&data.auditstate=="同意受理"){
                                            $.get('OperaQualityTable.html',function(OperaQualityTable) {
                                                index = layer.open({
                                                    type: 1,
                                                    title: '质量控制表',
                                                    content: OperaQualityTable,
                                                    area: ['auto', '600px'],
                                                    maxmin: false,
                                                    success:function (layero,index) {
                                                        $('input[name="shipname"]').attr("value",data.shipname);
                                                        $('input[name="rgstnum"]').attr("value",data.rgstnum);
                                                        $('input[name="qccdate"]').attr("value",getNowFormatDate())
                                                        $.ajax({
                                                            type: "GET",
                                                            url: contextPath + "/personal/info",
                                                            contentType: "application/json; charset=utf-8",
                                                            dataType: "json",
                                                            success: function (data) {
                                                                if(data.role=='验船师'){
                                                                    $('input[name="qccname"]').attr("value",data.name).attr('class','layui-input layui-disabled').attr('disabled',true);
                                                                }
                                                            },
                                                            error: function (e) {

                                                            }
                                                        });
                                                    },
                                                    yes: function(index) {
                                                        console.log(index);
                                                    },
                                                    full: function(elem) {
                                                        var win = window.top === window.self ? window : parent.window;
                                                        $(win).on('resize', function() {
                                                            var $this = $(this);
                                                            elem.width($this.width()).height($this.height()).css({
                                                                top: 0,
                                                                left: 0
                                                            });
                                                            elem.children('div.layui-layer-content').height($this.height() - 95);
                                                        });
                                                    }
                                                });
                                                form.render();
                                            });
                                        }else if(data.auditstate&&data.auditstate=="不予受理"){
                                            layer.msg('申请表已审核<br>不予受理' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }else{
                                            layer.msg('申请表未审核' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error: function (e) {

                                    }
                                });
                            }else if (data.role=="船厂"||data.role=="船东"||data.role=="负责人") {
                                $.ajax({
                                    type: "GET",
                                    url: contextPath + "/project/ops/" + rgstnum,
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    success: function (data) {
                                        if(data.state=="禁用"){
                                            layer.msg('该营运检验项目已被禁用' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }else if(!data.auditstate){
                                            layer.msg('申请表未审核' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }else if(data.auditstate&&data.auditstate=="不予受理"){
                                            layer.msg('申请表已审核<br>不予受理' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }else{
                                            layer.msg('质量控制表<br>未创建' , {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error: function (e) {

                                    }
                                });
                            }
                            else{

                            }
                        },
                        error: function (e) {

                        }
                    });
                }

            },
            error: function (e) {

            }
        });
    });


    $("body").on("click",".forbidd",function(){
        var rgstnum = $(this).data('id');

        layer.alert('是否禁用该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/ops/forbid/" + rgstnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    console.log(data.message);
                    if(data.message == "禁用营运检验成功!"){
                        layer.msg('禁用成功!<br>页面将在1秒后刷新...', {
                            time: 1000 //1s后自动关闭
                        });
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".reneww",function(){
        var rgstnum = $(this).data('id');

        layer.alert('是否恢复该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/ops/renew/" + rgstnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    console.log(data.message);
                    if(data.message == "恢复营运检验成功!"){
                        layer.msg('恢复成功!<br>页面将在1秒后刷新...', {
                            time: 1000 //1s后自动关闭
                        });
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".deletee",function(){
        var rgstnum = $(this).data('id');
        layer.alert('是否删除该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/ops/delete/" + rgstnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    console.log(data.message);
                    if(data.message == "删除营运检验成功!"){
                        layer.msg('删除成功!<br>页面将在1秒后刷新...');
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".moress",function(){
        var rgstnum = $(this).data('id');

        $.ajax({
            type: "GET",
            url: contextPath + "/project/ops/" + rgstnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
                $.get('OperaDetailsForm.html',function(OperaDetailsForm) {
                    index = layer.open({
                        type: 1,
                        title: '审核申请表',
                        content: OperaDetailsForm,
                        area: ['auto', '600px'],
                        maxmin: false,
                        success:function (layero,index) {
                            var ycs1infos = data.ycs1name+"/"+data.ycs1username;
                            var ycs2infos = data.ycs2name+"/"+data.ycs2username;
                            var ycs3infos = data.ycs3name+"/"+data.ycs3username;
                            var cdinfos = data.cdname+"/"+data.cdusername;

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/cd",
                                contentType: "application/json; charset=utf-8",
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="cdinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="cdinfo"]').val(cdinfos);
                                    form.render();
                                },
                                error:function (e) {
                                }
                            });

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/ycs",
                                contentType: "application/json; charset=utf-8",
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="ycs1info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                        $('select[name="ycs2info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                        $('select[name="ycs3info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="ycs1info"]').val(ycs1infos);
                                    $('select[name="ycs2info"]').val(ycs2infos);
                                    $('select[name="ycs3info"]').val(ycs3infos);
                                    form.render();
                                },
                                error:function (e) {
                                }
                            });

                            if(data.info1){
                                $('input[name="info1"]').attr("checked",true);
                                $('input[name="info1num"]').css("visibility",'visible');
                                $('#download1').css("visibility",'visible');
                                $('#download1').attr('href',contextPath+'/download?file='+data.info1adr);
                            }else{
                                $('input[name="info1"]').attr("checked",false);
                            }
                            if(data.info2){
                                $('input[name="info2"]').attr("checked",true);
                                $('input[name="info2num"]').css("visibility",'visible');
                                $('#download2').css("visibility",'visible');
                                $('#download2').attr('href',contextPath+'/download?file='+data.info2adr);
                            }else{
                                $('input[name="info2"]').attr("checked",false);
                            }
                            if(data.info3){
                                $('input[name="info3"]').attr("checked",true);
                                $('#download3').css("visibility",'visible');
                                $('#download3').attr('href',contextPath+'/download?file='+data.info3adr);
                            }else{
                                $('input[name="info3"]').attr("checked",false);
                            }
                            if(data.info4){
                                $('input[name="info4"]').attr("checked",true);
                                $('input[name="info4name"]').css("visibility",'visible');
                                $('#download4').css("visibility",'visible');
                                $('#download4').attr('href',contextPath+'/download?file='+data.info4adr);
                            }else{
                                $('input[name="info4"]').attr("checked",false);
                            }

                            $('input[name="shipname"]').attr("value",data.shipname);
                            $('input[name="insptype"]').attr("value",data.insptype);
                            $('select[name="insptype"]').val(data.insptype);
                            $('input[name="inspnum"]').attr("value",data.inspnum);
                            $('input[name="shiplength"]').attr("value",data.shiplength);
                            $('input[name="grosston"]').attr("value",data.grosston);
                            $('input[name="hostpower"]').attr("value",data.hostpower);
                            $('input[name="region"]').attr("value",data.region);
                            $('select[name="region"]').val(data.region);
                            $('input[name="shipstops"]').attr("value",data.shipstops);
                            $('input[name="shiptype"]').attr("value",data.shiptype);
                            $('input[name="inspaddress"]').attr("value",data.inspaddress);
                            $('input[name="dockingdate"]').attr("value",data.dockingdate);
                            $('input[name="apnttime"]').attr("value",data.apnttime);
                            $('input[name="cdinfo"]').attr("value",data.cdname+'/'+data.cdusername);
                            $('input[name="info4name"]').attr("value",data.info4name);
                            $('textarea[name="additional"]').val(data.additional);
                            $('input[name="apunitname"]').attr("value",data.apunitname);
                            $('input[name="fax"]').attr("value",data.fax);
                            $('input[name="zipcode"]').attr("value",data.zipcode);
                            $('input[name="crecode"]').attr("value",data.crecode);
                            $('input[name="writedate"]').attr("value",data.writedate);
                            $('input[name="ccadr"]').attr("value",data.ccadr);
                            $('input[name="writename"]').attr("value",data.writename);
                            var ccstr = data.ccinfo.split('/');
                            $('input[name="ccinfo"]').attr("value",ccstr[0]);
                            $('input[name="ccphone"]').attr("value",ccstr[1]);
                            $('textarea[name="remarks"]').val(data.remarks);

                            if(data.auditstate){
                                $('input[name="auditstate"]').attr("value",data.auditstate);
                                $('select[name="auditstate"]').val(data.auditstate);
                                $('input[name="auditdate"]').attr("value",data.auditdate);
                                if(chickInspnum(rgstnum)){
                                    $('#argstnumlabel').html("检验编号");
                                    $('input[name="argstnum"]').attr("value",data.rgstnum);
                                    $('input[name="argstnum"]').show();
                                }
                                if(data.auditstate == "不予受理"){
                                    $('textarea[name="auditopn"]').show();
                                    $('textarea[name="auditopn"]').val(data.auditopn);
                                } else{
                                    $('.operationGroup').show();
                                    if(data.headman==1){
                                        $('input:radio[name="headman1"][value="1"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="1"]').attr("checked",true);
                                    }else if(data.headman==2){
                                        $('input:radio[name="headman1"][value="2"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="2"]').attr("checked",true);
                                    }else if(data.headman==3){
                                        $('input:radio[name="headman1"][value="3"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="3"]').attr("checked",true);
                                    }else{
                                    }
                                    $('input[name="ycs1info"]').attr("value",ycs1infos);
                                    $('input[name="ycs2info"]').attr("value",ycs2infos);
                                    $('input[name="ycs3info"]').attr("value",ycs3infos);
                                }
                            }else{
                                $('.reviewResult').hide();
                            }

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/personal/role",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    console.log(data.role);
                                    if(data.role!="管理员"){
                                        $('#edit').hide();
                                    }
                                },
                                error: function (e) {

                                }
                            });
                            if(data.state=="禁用"){
                                $('#edit').hide();
                            }

                            //打印
                            $('#su').on('click',function () {
                                window.open('../../print/opera/OperaAppForm/OperaAForm.html?rgstnum='+rgstnum);
                            });

                            $('#edit').on('click',function () {
                                $('#xxx').hide();
                                $('#sss').show();
                                $('#insptype1').hide();
                                $('#insptype2').show();
                                $('#region1').hide();
                                $('#region2').show();
                                $('#auditstate1').hide();
                                $('#auditstate2').show();
                                $('.headman1').hide();
                                $('.headman2').show();
                                $('.groupinfo1').hide();
                                $('.groupinfo2').show();

                                $('input[name="shipname"]').attr('disabled', false);
                                $('input[name="insptype"]').attr('disabled', false);
                                $('input[name="shiplength"]').attr('disabled', false);
                                $('input[name="grosston"]').attr('disabled', false);
                                $('input[name="hostpower"]').attr('disabled', false);
                                $('input[name="region"]').attr('disabled', false);
                                $('input[name="shipstops"]').attr('disabled', false);
                                $('input[name="shiptype"]').attr('disabled', false);
                                $('input[name="inspaddress"]').attr('disabled', false);
                                $('input[name="dockingdate"]').attr('disabled', false);
                                $('input[name="apnttime"]').attr('disabled', false);
                                $('input[name="info4name"]').attr('disabled', false);
                                $('textarea[name="additional"]').attr('disabled', false);
                                $('textarea[name="remarks"]').attr('disabled', false);
                                $('input[name="auditstate"]').attr('disabled', false);
                                $('textarea[name="auditopn"]').attr('disabled', false);
                                $('input[name="auditdate"]').attr('disabled', false);

                                $('input[name="shipname"]').attr('class', 'layui-input');
                                $('input[name="insptype"]').attr('class', 'layui-input');
                                $('input[name="shiplength"]').attr('class', 'layui-input');
                                $('input[name="grosston"]').attr('class', 'layui-input');
                                $('input[name="hostpower"]').attr('class', 'layui-input');
                                $('input[name="region"]').attr('class', 'layui-input');
                                $('input[name="shipstops"]').attr('class', 'layui-input');
                                $('input[name="shiptype"]').attr('class', 'layui-input');
                                $('input[name="inspaddress"]').attr('class', 'layui-input');
                                $('input[name="dockingdate"]').attr('class', 'layui-input');
                                $('input[name="apnttime"]').attr('class', 'layui-input');
                                $('input[name="info4name"]').attr('class', 'layui-input');
                                $('textarea[name="additional"]').attr('class', 'layui-textarea');
                                $('textarea[name="remarks"]').attr('class', 'layui-textarea');
                                $('input[name="auditstate"]').attr('class', 'layui-input');
                                $('textarea[name="auditopn"]').attr('class', 'layui-textarea');
                                $('input[name="auditdate"]').attr('class', 'layui-input');

                            });

                            layero.find('input[name="shiplength"]').on("blur",function () {
                                var s = toDecimal2($(this).val());
                                if(s){
                                    $('input[name="shiplength"]').val(s);
                                }else{
                                    $('input[name="shiplength"]').val("");
                                }
                            });

                            layero.find('input[name="grosston"]').on("blur",function () {
                                var s = Math.round($(this).val());
                                if(s){
                                    $('input[name="grosston"]').val(s);
                                }else{
                                    $('input[name="grosston"]').val("");
                                }
                            });

                            layero.find('input[name="hostpower"]').on("blur",function () {
                                var s = toDecimal2($(this).val());
                                if(s){
                                    $('input[name="hostpower"]').val(s);
                                }else{
                                    $('input[name="hostpower"]').val("");
                                }
                            });

                            form.on('select(type)', function(data){
                                if(chickInspnum(rgstnum)){
                                    if(data.value == '不予受理'){
                                        $('.operationGroup').hide();
                                        $('textarea[name="auditopn"]').show();
                                        form.render();
                                    }else if(data.value == '同意受理'){
                                        $('.operationGroup').show();
                                        $('textarea[name="auditopn"]').hide();
                                        form.render();
                                    }else{

                                    }
                                }else{
                                    $('input[name="argstnum"]').attr('disabled', false);
                                    $('input[name="argstnum"]').attr('class', 'layui-input');
                                    if(data.value == '不予受理'){
                                        $('#argstnumlabel').html("");
                                        $('input[name="argstnum"]').hide();
                                        $('.operationGroup').hide();
                                        $('textarea[name="auditopn"]').show();
                                        form.render();
                                    }else if(data.value == '同意受理'){
                                        $('#argstnumlabel').html("检验编号");
                                        $('input[name="argstnum"]').show();
                                        $('.operationGroup').show();
                                        $('textarea[name="auditopn"]').hide();
                                        form.render();
                                    }else{
                                        
                                    }
                                }
                            });

                            form.on('select(insptypefilter)', function(data){
                                if(data.value == '其他'){
                                    layer.prompt({
                                        formType: 0,
                                        value:'',
                                        maxlength: 10,
                                        title: '请输入其他检验类型'
                                    }, function(value, index, elem){
                                        console.log(value);
                                        $('select[name="insptype"]').append("<option value='"+value+"'>"+value+"</option>");
                                        $('select[name="insptype"]').val(value);
                                        layer.close(index);
                                        $('select[name="insptype"] option').each(function() {
                                            var val = $(this).val();
                                            if($("select[name='insptype'] option[value='" + val + "']").length > 1 ){
                                                $("select[name='insptype'] option[value='" + val + "']:gt(0)").remove();
                                            }
                                        });
                                        form.render();
                                    });  
                                }
                            });

                            form.on('select(regionfilter)', function(data){
                                if(data.value == '其他'){
                                    layer.prompt({
                                        formType: 0,
                                        value:'',
                                        maxlength: 10,
                                        title: '请输入其他航行区域'
                                    }, function(value, index, elem){
                                        console.log(value);
                                        $('select[name="region"]').append("<option value='"+value+"'>"+value+"</option>");
                                        $('select[name="region"]').val(value);
                                        layer.close(index);
                                        $('select[name="region"] option').each(function() {
                                            var val = $(this).val();
                                            if($("select[name='region'] option[value='" + val + "']").length > 1 ){
                                                $("select[name='region'] option[value='" + val + "']:gt(0)").remove();
                                            }
                                        });
                                        form.render();
                                    });  
                                }
                            });

                            $('#submit').on('click',function () {
                                var ss = new Object();

                                ss.shipname = $('input[name="shipname"]').val();
                                ss.insptype = $('select[name="insptype"] option:selected').val();
                                ss.rgstnum = rgstnum;
                                ss.inspnum = $('input[name="inspnum"]').val();
                                ss.shiplength = $('input[name="shiplength"]').val();
                                ss.grosston = $('input[name="grosston"]').val();
                                ss.hostpower = $('input[name="hostpower"]').val();
                                ss.region = $('select[name="region"] option:selected').val();
                                ss.shipstops = $('input[name="shipstops"]').val();
                                ss.shiptype = $('input[name="shiptype"]').val();
                                ss.inspaddress = $('input[name="inspaddress"]').val();
                                ss.dockingdate = $('input[name="dockingdate"]').val();
                                ss.apnttime = $('input[name="apnttime"]').val();
                                if($('select[name="cdinfo"] option:selected').val()){
                                    ss.cdinfo = $('select[name="cdinfo"] option:selected').val();
                                }else{
                                    ss.cdinfo = "";
                                }
                                ss.additional = $('textarea[name="additional"]').val();
                                ss.apunitname = $('input[name="apunitname"]').val();
                                ss.fax = $('input[name="fax"]').val();
                                ss.zipcode = $('input[name="zipcode"]').val();
                                ss.crecode = $('input[name="crecode"]').val();
                                ss.writedate = $('input[name="writedate"]').val();
                                ss.ccadr = $('input[name="ccadr"]').val();
                                ss.writename = $('input[name="writename"]').val();
                                ss.ccinfo = $('input[name="ccinfo"]').val()+"/"+$('input[name="ccphone"]').val();
                                ss.remarks = $('textarea[name="remarks"]').val();

                                var message1="",message2="";

                                $.ajax({
                                    type:"PUT",
                                    url:contextPath+"/project/ops/update/cc",
                                    async: false,
                                    contentType: "application/json; charset=utf-8",
                                    data:JSON.stringify(ss),
                                    dataType:"json",
                                    success:function (data) {
                                        message1=data.message;
                                    },
                                    error:function (e) {
                                    }
                                });


                                if($('select[name="auditstate"] option:selected').val()){
                                    var sss = new Object();

                                    sss.rgstnum = rgstnum;
                                    sss.auditstate = $('select[name="auditstate"] option:selected').val();
                                    if(chickInspnum(rgstnum)){
                                        sss.argstnum = "";
                                    }else{
                                        sss.argstnum = $('input[name="argstnum"]').val();
                                    }
                                    if(sss.auditstate=='不予受理'){
                                        sss.auditopn = $('textarea[name="auditopn"]').val();
                                        sss.headman = 0;
                                        sss.ycs1info = "";
                                        sss.ycs2info = "";
                                        sss.ycs3info = "";
                                    }else{
                                        sss.auditopn = ""
                                        sss.headman = $('input[name="headman2"]:checked').val();
                                        sss.ycs1info = $('select[name="ycs1info"] option:selected').val();
                                        sss.ycs2info = $('select[name="ycs2info"] option:selected').val();
                                        sss.ycs3info = $('select[name="ycs3info"] option:selected').val();
                                    }

                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/ops/update/cjc",
                                        async: false,
                                        contentType: "application/json; charset=utf-8",
                                        data: JSON.stringify(sss),
                                        dataType:"json",
                                        success:function (data) {
                                            message2 = data.message;
                                        },
                                        error:function (e) {
                                        }
                                    });
                                }
                                
                                if(message2!=""){
                                    if(message1 == "更新成功!"&message2 == "更新成功!"){
                                        layer.msg('营运检验申请表更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        if(message1 == "更新成功!"){
                                            message1 = "新建申请表模块 "+message1;
                                        }else{
                                            message1 = "<b style='color:red'>新建申请表模块 更新失败!<br>"+message1+"</b>";
                                        }
                                        if(message2 == "更新成功!"){
                                            message2 = "审核申请表模块 "+message2;
                                        }else{
                                            message2 = "<b style='color:red'>审核申请表模块 更新失败!<br>"+message2+"</b>";
                                        }
                                        layer.msg(message1+'<br><br>'+message2, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }else{
                                    if(message1 == "更新成功!"){
                                        layer.msg('营运检验申请表更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        layer.msg(message1, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }

                                return false;
                            });

                        },
                        yes: function(index) {
                            console.log(index);
                        },
                        full: function(elem) {
                            var win = window.top === window.self ? window : parent.window;
                            $(win).on('resize', function() {
                                var $this = $(this);
                                elem.width($this.width()).height($this.height()).css({
                                    top: 0,
                                    left: 0
                                });
                                elem.children('div.layui-layer-content').height($this.height() - 95);
                            });
                        }
                    });
                    form.render();
                });
            },
            error: function (e) {

            }
        });

    });

    $("body").on("click",".moress1",function(){
        var rgstnum = $(this).data('id');

        $.ajax({
            type: "GET",
            url: contextPath + "/project/ops/" + rgstnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.state=="禁用"){
                    layer.msg('该营运检验项目已被禁用' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else if(!data.auditstate){
                $.get('OperaAppForm.html',function(OperaAppForm) {
                    index = layer.open({
                        type: 1,
                        title: '审核申请表',
                        content: OperaAppForm,
                        area: ['auto', '600px'],
                        maxmin: false,
                        success:function (layero,index) {
                            if(data.info1){
                                $('input[name="info1"]').attr("checked",true);
                                $('input[name="info1num"]').css("visibility",'visible');
                                $('#download1').css("visibility",'visible');
                                $('#download1').attr('href',contextPath+'/download?file='+data.info1adr);
                            }else{
                                $('input[name="info1"]').attr("checked",false);
                            }
                            if(data.info2){
                                $('input[name="info2"]').attr("checked",true);
                                $('input[name="info2num"]').css("visibility",'visible');
                                $('#download2').css("visibility",'visible');
                                $('#download2').attr('href',contextPath+'/download?file='+data.info2adr);
                            }else{
                                $('input[name="info2"]').attr("checked",false);
                            }
                            if(data.info3){
                                $('input[name="info3"]').attr("checked",true);
                                $('#download3').css("visibility",'visible');
                                $('#download3').attr('href',contextPath+'/download?file='+data.info3adr);
                            }else{
                                $('input[name="info3"]').attr("checked",false);
                            }
                            if(data.info4){
                                $('input[name="info4"]').attr("checked",true);
                                $('input[name="info4name"]').css("visibility",'visible');
                                $('#download4').css("visibility",'visible');
                                $('#download4').attr('href',contextPath+'/download?file='+data.info4adr);
                            }else{
                                $('input[name="info4"]').attr("checked",false);
                            }

                            $('input[name="shipname"]').attr("value",data.shipname);
                            $('input[name="insptype"]').attr("value",data.insptype);
                            $('input[name="inspnum"]').attr("value",data.inspnum);
                            $('input[name="shiplength"]').attr("value",data.shiplength);
                            $('input[name="grosston"]').attr("value",data.grosston);
                            $('input[name="hostpower"]').attr("value",data.hostpower);
                            $('input[name="region"]').attr("value",data.region);
                            $('input[name="shipstops"]').attr("value",data.shipstops);
                            $('input[name="shiptype"]').attr("value",data.shiptype);
                            $('input[name="inspaddress"]').attr("value",data.inspaddress);
                            $('input[name="dockingdate"]').attr("value",data.dockingdate);
                            $('input[name="apnttime"]').attr("value",data.apnttime);
                            $('input[name="cdinfo"]').attr("value",data.cdname+'/'+data.cdusername);
                            $('input[name="info4name"]').attr("value",data.info4name);
                            $('textarea[name="additional"]').val(data.additional);
                            $('input[name="apunitname"]').attr("value",data.apunitname);
                            $('input[name="fax"]').attr("value",data.fax);
                            $('input[name="zipcode"]').attr("value",data.zipcode);
                            $('input[name="crecode"]').attr("value",data.crecode);
                            $('input[name="writedate"]').attr("value",data.writedate);
                            $('input[name="ccadr"]').attr("value",data.ccadr);
                            $('input[name="writename"]').attr("value",data.writename);
                            var ccstr = data.ccinfo.split('/');
                            $('input[name="ccinfo"]').attr("value",ccstr[0]);
                            $('input[name="ccphone"]').attr("value",ccstr[1]);
                            $('textarea[name="remarks"]').val(data.remarks);

                            $( document ).ready(function() {
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/user/ycs",
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data[0].name);
                                        for(var i=0; i<data.length; i++){
                                            $('select[name="ycs1info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                            $('select[name="ycs2info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                            $('select[name="ycs3info"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                        }
                                        form.render();
                                    },
                                    error:function (e) {
                                    }
                                });
                            });
                            $('input[name="auditdate"]').attr("value",getNowFormatDate());

                            form.on('submit(ca)', function(data) {
                                $(this).attr('disabled','disabled');
                                var OperaAppForm = new Object();
                                OperaAppForm.rgstnum =  rgstnum;
                                OperaAppForm.argstnum =  $('input[name="argstnum"]').val();
                                OperaAppForm.ycs1info = $("select[name='ycs1info'] option:selected").val();
                                OperaAppForm.ycs2info = $("select[name='ycs2info'] option:selected").val();
                                OperaAppForm.ycs3info = $("select[name='ycs3info'] option:selected").val();
                                if($("input[name='headman']:checked").val()){
                                    OperaAppForm.headman = $("input[name='headman']:checked").val();
                                }else{
                                    OperaAppForm.headman = 0;
                                }
                                OperaAppForm.auditstate = $("select[name='auditstate'] option:selected").val();
                                OperaAppForm.auditopn = data.field.auditopn;
                                console.log(JSON.stringify(OperaAppForm));

                                $.ajax({
                                    type:"PUT",
                                    url:contextPath+"/project/ops/update/cjc",
                                    contentType: "application/json; charset=utf-8",
                                    data: JSON.stringify(OperaAppForm),
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data.message);
                                        if(data.message == "更新成功!"){
                                            layer.closeAll();
                                            layer.msg('提交评审成功!<br>页面将在1秒后刷新...');
                                            setTimeout(function(){window.location.reload();},1000);
                                        } else {
                                            $('#su').attr('disabled',false);
                                            layer.msg(data.message, {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                            $("#all-info").html("*"+data.message);
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });

                                return false;
                            });
                        },
                        yes: function(index) {
                            console.log(index);
                        },
                        full: function(elem) {
                            var win = window.top === window.self ? window : parent.window;
                            $(win).on('resize', function() {
                                var $this = $(this);
                                elem.width($this.width()).height($this.height()).css({
                                    top: 0,
                                    left: 0
                                });
                                elem.children('div.layui-layer-content').height($this.height() - 95);
                            });
                        }
                    });
                    form.render();
                });
                }else {
                    layer.msg('该申请表已审核完毕<br>'+data.auditstate , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }

            },
            error: function (e) {
            }
        });

    });

    $('body').on('click', '#close', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closes', function(){
        layer.close(index);
        return false;
    });

    $('#search').on('click', function() {
        var type = $('#search_type').val();
        var value = $('#search_value').val();
        $('#s_type').attr("value",type);
        $('#s_value').attr("value",value);
        if(value === '' || value.length === 0) {
            layer.msg('请输入关键字！',{
                time:2000
            });
            return ;
        }

        paging.get({
            value: value,
            type: type
        });
    });

    $('#showall').on('click', function() {
        $('#search_type').val("");
        $('#search_value').val("");
        $('#s_type').removeAttr("value");
        $('#s_value').removeAttr("value");
        form.render();
        paging.get({
            value: null,
            type: null
        });
    });

    $('#add').on('click', function() {
        $.get('OperaNewItems.html', null, function(OperaNewItems) {
            layer.open({
                type: 1,
                title: '新建营运检验申请表',
                content: OperaNewItems,
                area: ['auto', '600px'],
                maxmin: false,
                success:function (layero,index) {
                    layero.find("#closex").on("click",function () {
                        layer.closeAll();
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/user/cd",
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            console.log(data[0].name);
                            for(var i=0; i<data.length; i++){
                                $('select[name="cdinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                            }
                            form.render();
                        },
                        error:function (e) {

                        }
                    });

                    if(therole=="管理员"||therole=="船东"){
                        $('#chosecc').show();
                        $.ajax({
                            type:"GET",
                            url:contextPath+"/user/cc",
                            contentType: "application/json; charset=utf-8",
                            dataType:"json",
                            success:function (data) {
                                for(var i=0; i<data.length; i++){
                                    $('select[name="cc"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                }
                                form.render();
                            },
                            error:function (e) {
                            }
                        });
                    }  

                    $.ajax({
                        type: "GET",
                        url: contextPath + "/personal/info",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if(data.role=="船东"){
                                $('select[name="cdinfo"]').val(data.name+"/"+data.username);
                            }
                            if(data.fax&&data.zipcode&&data.crecode&&data.ccadr&&data.writename){
                                $('input[name="apunitname"]').attr("value",data.coname);
                                $('input[name="ccinfo"]').attr("value",data.name);
                                $('input[name="ccphone"]').attr("value",data.username);
                                $('input[name="fax"]').attr("value",data.fax);
                                $('input[name="zipcode"]').attr("value",data.zipcode);
                                $('input[name="crecode"]').attr("value",data.crecode);
                                $('input[name="ccadr"]').attr("value",data.ccadr);
                                $('input[name="writename"]').attr("value",data.writename);
                                $('input[name="apunitname"]').attr("disabled",true);
                                $('input[name="ccinfo"]').attr("disabled",true);
                                $('input[name="ccphone"]').attr("disabled",true);
                                $('input[name="fax"]').attr("disabled",true);
                                $('input[name="zipcode"]').attr("disabled",true);
                                $('input[name="crecode"]').attr("disabled",true);
                                $('input[name="ccadr"]').attr("disabled",true);
                                $('input[name="writename"]').attr("disabled",true);
                            }
                        },
                        error: function (e) {

                        }
                    });
                    $('input[name="writedate"]').attr("value",getNowFormatDate())

                    var OperaNewItems = new Object();

                    layero.find('input[name="shiplength"]').on("blur",function () {
                        var s = toDecimal2($(this).val());
                        if(s){
                            $('input[name="shiplength"]').val(s);
                        }else{
                            $('input[name="shiplength"]').val("");
                        }
                    });

                    layero.find('input[name="grosston"]').on("blur",function () {
                        var s = Math.round($(this).val());
                        if(s){
                            $('input[name="grosston"]').val(s);
                        }else{
                            $('input[name="grosston"]').val("");
                        }
                    });

                    layero.find('input[name="hostpower"]').on("blur",function () {
                        var s = toDecimal2($(this).val());
                        if(s){
                            $('input[name="hostpower"]').val(s);
                        }else{
                            $('input[name="hostpower"]').val("");
                        }
                    });

                    $('#download1').on('click',function () {
                        if( !ConstNewItems.info1adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download2').on('click',function () {
                        if( !ConstNewItems.info2adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download3').on('click',function () {
                        if( !ConstNewItems.info3adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download4').on('click',function () {
                        if( !ConstNewItems.info4adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $.ajax({
                        type: "GET",
                        url: contextPath + "/personal/info",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            var username = "opera"+data.username; 

                            upload.render({
                                elem: '#file1'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file1'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        OperaNewItems.info1adr = res.data.url;
                                        $('#download1').attr("href",contextPath+"/download?file="+res.data.url);
                                        $('#download1').css("visibility",'visible');
                                        layer.msg('船检证书正本上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file2'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file2'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        OperaNewItems.info2adr = res.data.url;
                                        $('#download2').attr("href",contextPath+"/download?file="+res.data.url);
                                        $('#download2').css("visibility",'visible');
                                        layer.msg('船舶修理项目单上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file3'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file3'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        OperaNewItems.info3adr = res.data.url;
                                        $('#download3').attr("href",contextPath+"/download?file="+res.data.url);
                                        $('#download3').css("visibility",'visible');
                                        layer.msg('委托书上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file4'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file4'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        OperaNewItems.info4adr = res.data.url;
                                        $('#download4').attr("href",contextPath+"/download?file="+res.data.url);
                                        $('#download4').css("visibility",'visible');
                                        layer.msg('其他有关资料上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                        },
                        error: function (e) {

                        }
                    });
                    
                    form.on('checkbox(info1)', function(data){
                        if(data.elem.checked){
                            $('#span1').css("color","black");
                            $('#file1').css("visibility",'visible');

                            OperaNewItems.info1 = true;
                        } else {
                            $('#span1').css("color","grey");
                            $('#file1').css("visibility",'hidden');
                            $('#download1').css("visibility",'hidden');

                            console.log(OperaNewItems.info1adr);
                            if(OperaNewItems.info1adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+OperaNewItems.info1adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            OperaNewItems.info1 = false;
                            OperaNewItems.info1adr = "";
                        }
                    });

                    form.on('checkbox(info2)', function(data){
                        if(data.elem.checked){
                            $('#span2').css("color","black");
                            $('#file2').css("visibility",'visible');

                            OperaNewItems.info2 = true;
                        } else {
                            $('#span2').css("color","grey");
                            $('#file2').css("visibility",'hidden');
                            $('#download2').css("visibility",'hidden');

                            if(OperaNewItems.info2adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+OperaNewItems.info2adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            OperaNewItems.info2 = false;
                            OperaNewItems.info2adr = "";
                        }
                    });

                    form.on('checkbox(info3)', function(data){
                        if(data.elem.checked){
                            $('#span3').css("color","black");
                            $('#file3').css("visibility",'visible');

                            OperaNewItems.info3 = true;
                        } else {
                            $('#span3').css("color","grey");
                            $('#file3').css("visibility",'hidden');
                            $('#download3').css("visibility",'hidden');

                            if(OperaNewItems.info3adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+OperaNewItems.info3adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });;
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            OperaNewItems.info3 = false;
                            OperaNewItems.info3adr = "";
                        }
                    });

                    form.on('checkbox(info4)', function(data){
                        if(data.elem.checked){
                            $('#span4').html('其他&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名称');
                            $('#span4').css("color","black");
                            $('input[name="info4name"]').css("visibility",'visible');
                            $('#file4').css("visibility",'visible');

                            OperaNewItems.info4 = true;
                        } else {
                            $('#span4').html('其他');
                            $('#span4').css("color","grey");
                            $('input[name="info4name"]').css("visibility",'hidden');
                            $('#file4').css("visibility",'hidden');
                            $('#download4').css("visibility",'hidden');

                            if(OperaNewItems.info4adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+OperaNewItems.info4adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time:false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            OperaNewItems.info4 = false;
                            OperaNewItems.info4name = "";
                            OperaNewItems.info4adr = "";
                        }
                    });

                    //监听提交
                    form.on('submit(caseglyx)', function(data) {
                        $(this).attr('disabled','disabled');

                        OperaNewItems.shipname = data.field.shipname;
                        OperaNewItems.insptype = data.field.insptype;
                        OperaNewItems.inspnum = data.field.inspnum;
                        OperaNewItems.shiplength = data.field.shiplength;
                        OperaNewItems.grosston = data.field.grosston;
                        OperaNewItems.hostpower = data.field.hostpower;
                        OperaNewItems.region = data.field.region;
                        OperaNewItems.shipstops = data.field.shipstops;
                        OperaNewItems.shiptype = data.field.shiptype;
                        OperaNewItems.inspaddress = data.field.inspaddress;
                        OperaNewItems.dockingdate = data.field.dockingdate;
                        OperaNewItems.apnttime = data.field.apnttime;
                        OperaNewItems.cdinfo = data.field.cdinfo;
                        if(OperaNewItems.info1){

                        } else{
                            OperaNewItems.info1 = false;
                            OperaNewItems.info1adr = "";
                        }
                        if(OperaNewItems.info2){

                        } else{
                            OperaNewItems.info2 = false;
                            OperaNewItems.info2adr = "";
                        }
                        if(OperaNewItems.info3){

                        } else{
                            OperaNewItems.info3 = false;
                            OperaNewItems.info3adr = "";
                        }
                        if(OperaNewItems.info4){
                            OperaNewItems.info4name = $('input[name="info4name"]').val();
                        } else{
                            OperaNewItems.info4 = false;
                            OperaNewItems.info4name = "";
                            OperaNewItems.info4adr = "";
                        }
                        OperaNewItems.additional = data.field.additional;
                        OperaNewItems.apunitname = data.field.apunitname;
                        OperaNewItems.fax = data.field.fax;
                        OperaNewItems.zipcode = data.field.zipcode;
                        OperaNewItems.crecode = data.field.crecode;
                        OperaNewItems.ccadr = data.field.ccadr;
                        OperaNewItems.writename = data.field.writename;
                        OperaNewItems.ccinfo = data.field.ccinfo+"/"+data.field.ccphone;
                        OperaNewItems.remarks  = data.field.remarks;

                        console.log(JSON.stringify(OperaNewItems));

                        $.ajax({
                            type:"POST",
                            url:contextPath+"/project/ops/new/cc",
                            contentType: "application/json; charset=utf-8",
                            data:JSON.stringify(OperaNewItems),
                            dataType:"json",
                            success:function (data) {
                                console.log(data.message);
                                if(data.message == "创建成功!"){
                                    layer.msg('营运检验申请表创建成功!<br>页面将在1秒后刷新...');
                                    setTimeout(function(){window.location.reload();},1000);
                                } else {
                                    $('#suresubmitx').attr('disabled',false);
                                    layer.msg(data.message, {
                                        time:false,
                                        btn:"确定",
                                        btnAlign: 'c'
                                    });
                                }
                            },
                            error:function (e) {
                            }
                        });
                        return false;
                    });

                },
                yes: function(index) {
                    console.log(index);
                },
                full: function(elem) {
                    var win = window.top === window.self ? window : parent.window;
                    $(win).on('resize', function() {
                        var $this = $(this);
                        elem.width($this.width()).height($this.height()).css({
                            top: 0,
                            left: 0
                        });
                        elem.children('div.layui-layer-content').height($this.height() - 95);
                    });
                }
            });
            form.render();
        });
    });

    $('.site-table tbody tr').on('click', function(event) {
        var $this = $(this);
        var $input = $this.children('td').eq(0).find('input');
        $input.on('ifChecked', function(e) {
            $this.css('background-color', '#EEEEEE');
        });
        $input.on('ifUnchecked', function(e) {
            $this.removeAttr('style');
        });
        $input.iCheck('toggle');
    }).find('input').each(function() {
        var $this = $(this);
        $this.on('ifChecked', function(e) {
            $this.parents('tr').css('background-color', '#EEEEEE');
        });
        $this.on('ifUnchecked', function(e) {
            $this.parents('tr').removeAttr('style');
        });
    });

    exports('OperaItemsList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});